import React from 'react';
import {
    ActivityIndicator,
    Button,
    Text,
    View,
    Image,
    StyleSheet,
    Dimensions,
    StatusBar,
    FlatList,
    ScrollView,
    RefreshControl,
    Animated,
    TouchableHighlight,
    SectionList, TouchableOpacity, DeviceEventEmitter, TextInput, Modal
} from 'react-native';


//引入
import { createBottomTabNavigator } from 'react-navigation-tabs';
import { WebView } from 'react-native-webview'
import Ugame from '../../../../Ugame';
import DLTBall from "./DLTBall";
const { width, height } = Dimensions.get('window')
var BETTYPE = {
    One: 0,
    Multiple: 1,
    Bladder: 2
}
export default class DLTChart extends React.Component {
    constructor(props) {
        super(props);
        this.state = {
            baseUrl: (Platform.OS === 'ios') ? { uri: './assets/dlt.html' } : { uri: 'file:///android_asset/dlt.html' }
        };
    }
    static navigationOptions = {
        title: '走势图',
        //header: null,  //隐藏顶部导航栏
        //tabBarVisible: false, // 隐藏底部导航栏
        headerStyle: {
            backgroundColor: '#d0162e',
        },
        headerTintColor: '#fff',
        headerTitleStyle: {
            //fontWeight: 'bold',
        },
    }
    componentWillMount() {

    }
    componentWillUnmount() {

    }
    componentDidMount() {

    }
    onMessage() {
        (event) => {
            console.log(event.nativeEvent.data);
            alert(event.nativeEvent.data);
        }
    }
    _onMessage=(event)=>{
        console.log(event.nativeEvent.data);

        let info = event.nativeEvent.data;
        //Model=DLTGame&Number=2020021&betCode=01,02,03,04,05,06,07,08|01,02&count=56&money=112
        info = info.split('&');
        let Model = info[0].split('=')[1];
        let Number = info[1].split('=')[1];
        let betCode = info[2].split('=')[1];
        let red_ball = betCode.split('|')[0].split(',');
        let blue_ball = betCode.split('|')[1].split(',');
        if (red_ball.length == 5 && blue_ball.length == 2) {
            type = BETTYPE.One;
        } else {
            type = BETTYPE.Multiple
        }
        let obj = DLTBall.betNumberComb(type, Number, [], red_ball, [], blue_ball, 1);
        let array = [obj];
        Ugame.addDLTSelectList(array);
        this.props.navigation.navigate('DLTBetList', {
            Number: Number
        });
    }
    render() {
        let { baseUrl } = this.state;
        if (baseUrl == null) {
            return (
                <View></View>
            );
        }
        const injectedJavascript = `(function() {
            window.postMessage = function(data) {
              window.ReactNativeWebView.postMessage(data);
            };
          })()`;
        return (
            <View style={Styles.container}>
                <StatusBar translucent={true} backgroundColor="transparent" />
                <WebView
                    useWebKit={true}
                    source={baseUrl}
                    injectedJavaScript={injectedJavascript}
                    onMessage={this._onMessage}
                />
            </View>
        )
    }
}
var Styles = StyleSheet.create({
    container: {
        flex: 1,
        width: width,
        height: createBottomTabNavigator.DEFAULT_HEIGHT,
        backgroundColor: '#ffffff'
    },
});